#!/bin/bash
###
 # @Author: Lai Jun
 # @E-mail: laijun@nudt.edu.cn
 # @LastEditors: Lai Jun
 # @LastEditTime: 2022-06-26 22:11:33
### 
# 在ubuntu 20.04中安装ros noetic以及gazebo的相关组件

# check whether in windows 10 bash (wsl)

if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then
    IN_WSL=true
else
    IN_WSL=false
fi

ROS_DIST=noetic
UBUNTU_DIST=$(lsb_release -sc)
sudo bash -c "echo \"deb https://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $UBUNTU_DIST main\" > /etc/apt/sources.list.d/ros-latest.list && apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654"

sudo apt-get update 
sudo apt-get install -y ros-$ROS_DIST-desktop
sudo apt-get install -y ros-$ROS_DIST-gazebo-ros-pkgs ros-$ROS_DIST-gazebo-ros-control
sudo apt-get install -y ros-$ROS_DIST-mavros ros-$ROS_DIST-mavros-extras ros-$ROS_DIST-control-toolbox


sudo apt install python3-pip wget lsb-release gnupg curl


# if in WSL, then 
if [[ IN_WSL ]]; then
    echo "WSL中建立cuda环境，需要吗"
    read -p "y or Y for yes, otherwise no" yes
    if [[ $yes == "y" || $yes == "Y" ]]; then
        echo "执行中..."
    else
        exit 0
    fi
    sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
    sudo sh -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
    sudo apt-get update
    sudo apt-get install -y cuda-toolkit-11-0
fi